﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Circle.Web.Application.Api;
using Circle.Domain.Interface.Service;
using Circle.Web.ViewModelsClient;
using System.Web.Http;
using Circle.Domain.Model;
using Circle.Manager;

namespace Circle.Website.Controllers.Api
{
    public class VoteController : BaseApiController
    {

        private readonly IVoteService _voteService;

        public VoteController()
        {
            _voteService = DependencyResolver.Current.GetService<IVoteService>();
        }

        [System.Web.Http.HttpPost]
        public string VoteUp([FromBody]string jsonModel)
        {
            VoteClientModel vote = ClientModel.FromJson<VoteClientModel>(jsonModel);
            var status = _voteService.VoteUp(vote.CommentId);
            if (status == OperationStatus.Success)
            {
                vote.VoteUpCount++;
               
            }

            
            return vote.ToJson();
        }

        [System.Web.Http.HttpPost]
        public string VoteDown([FromBody]string jsonModel)
        {
            VoteClientModel vote = ClientModel.FromJson<VoteClientModel>(jsonModel);
            var status = _voteService.VoteDown(vote.CommentId);
            vote.VoteDownCount++;

            return vote.ToJson();
        }
    }
}
